package com.linsir.ext.jfinal;

import com.jfinal.plugin.activerecord.DbPro;
import com.jfinal.plugin.activerecord.Record;
import com.linsir.common.utils.xx;
import com.linsir.config.EovaConst;

/**
 * @author yuxiaolin
 * @title: EovaDbPro
 * @projectName linsir-mu
 * @description: 拓展默认Db操作<br>
 *  * 1.常用聚合API自动类型转换,使用更顺滑<br>
 *  * 2.Eova Oracle序列的自动识别
 * @date 2021/12/3 10:34 AM
 */

public class EovaDbPro extends DbPro {

    public EovaDbPro(String configName) {
        super(configName);
    }

    @Override
    public boolean save(String tableName, String primaryKey, Record record) {
        // Oracle 并且是单主键 设置默认序列
        if (xx.isOracle() && !primaryKey.contains(",") && record.get(primaryKey) == null) {
            record.set(primaryKey, EovaConst.SEQ_ + tableName + ".nextval");
        }
        return super.save(tableName, primaryKey, record);
    }
}
